<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>111111111111</title>
  <style>
    .submit{
      width: 100px;
      height: 40px;
      background-color:purple;
      color: #fff;
      text-align: center;
      line-height: 40px;
    }
  </style>
</head>
<body>
     <ul>
       <li>
         <span>账号</span>
         <input type="text" id="username"/>
       </li>
       <li>
         <span>密码</span>
         <input type="text" id="pwd"/>
       </li>
       <li class="submit">
          提交
       </li>
     </ul>
</body>
<script src="./js/axios.js"></script>
<script>
    var username = document.getElementById("username");
    var pwd = document.getElementById("pwd")
    var submit = document.getElementsByClassName("submit")[0]
    submit.addEventListener("click",function () {
        login();
    })

    function login() {
        console.log("username)_)__)_)_")
        console.log(username.value)
        console.log("pwd__+_+_+_+_+_+_+")
        console.log(pwd.value)
        var params = new URLSearchParams();
        params.append('password',username.value);
        params.append('user_name',pwd.value);
        axios.post('/admin/login', params)
            .then(function (e) {
//              console.log(e)
              console.log("succcess))_)_)_)_)")
              console.log(e)
            })
            .catch(function (error) {
                console.log(error);
            });
    }


    //异常提交
    window.onerror = function(msg,url,line,col,error){
        //没有URL不上报！上报也不知道错误
        if (msg != "Script error." && !url){
            return true;
        }
        //采用异步的方式
        //我遇到过在window.onunload进行ajax的堵塞上报
        //由于客户端强制关闭webview导致这次堵塞上报有Network Error
        //我猜测这里window.onerror的执行流在关闭前是必然执行的
        //而离开文章之后的上报对于业务来说是可丢失的
        //所以我把这里的执行流放到异步事件去执行
        //脚本的异常数降低了10倍
        setTimeout(function(){
            var data = {};
            //不一定所有浏览器都支持col参数
            col = col || (window.event && window.event.errorCharacter) || 0;

            data.url = url;
            data.line = line;
            data.col = col;
            if (!!error && !!error.stack){
                //如果浏览器有堆栈信息
                //直接使用
                data.msg = error.stack.toString();
            }else if (!!arguments.callee){
                //尝试通过callee拿堆栈信息
                var ext = [];
                var f = arguments.callee.caller, c = 3;
                //这里只拿三层堆栈信息
                while (f && (--c>0)) {
                    ext.push(f.toString());
                    if (f  === f.caller) {
                        break;//如果有环
                    }
                    f = f.caller;
                }
                ext = ext.join(",");
                data.msg = ext;
            }
            //把data上报到后台！
        },0);
        return true;
    };
</script>
</html>